Conditions | 1 |
Paths | 1 |
Total Lines | 129 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var chai = require('chai'); |
||
430 | function tests(gedx){ |
||
431 | assert.equal(gedx.getId(), 'gedcomx'); |
||
432 | assert.equal(gedx.getLang(), 'en'); |
||
433 | assert.equal(gedx.getDescription(), '#sd1'); |
||
434 | |||
435 | var attribution = gedx.getAttribution(); |
||
436 | assert.equal(attribution.getChangeMessage(), 'It changed', 'Change message not saved properly when created with JSON'); |
||
437 | assert.equal(attribution.getContributor().getResource(), 'https://myapp.com/contributor', 'Contributor not saved when created with JSON'); |
||
438 | assert.equal(attribution.getCreated().getTime(), 1111338494969, 'Created date not saved when created with JSON'); |
||
439 | assert.equal(attribution.getCreator().getResource(), 'https://myapp.com/creator', 'Creator not saved when created with JSON'); |
||
440 | assert.equal(attribution.getModified().getTime(), 1111338494969, 'Modified date not saved when created with JSON'); |
||
441 | |||
442 | assert.equal(gedx.getPersons().length, 1); |
||
443 | var person = gedx.getPersons()[0]; |
||
444 | assert.equal(person.getGender().getType(), 'http://gedcomx.org/Female'); |
||
445 | assert.equal(person.getNames().length, 1); |
||
446 | assert.equal(person.getFacts().length, 1); |
||
447 | |||
448 | assert.equal(gedx.getRelationships().length, 1); |
||
449 | var relationship = gedx.getRelationships()[0]; |
||
450 | assert.equal(relationship.getType(), 'http://gedcomx.org/Couple'); |
||
451 | assert.equal(relationship.getPerson1().getResource(), 'http://identifier/for/person/1'); |
||
452 | assert.equal(relationship.getPerson2().getResource(), 'http://identifier/for/person/2'); |
||
453 | assert.equal(relationship.getFacts().length, 1); |
||
454 | assert.equal(relationship.getFacts()[0].getType(), 'http://gedcomx.org/Marriage'); |
||
455 | |||
456 | assert.equal(gedx.getSourceDescriptions().length, 1); |
||
457 | var description = gedx.getSourceDescriptions()[0]; |
||
458 | assert.equal(description.getId(), 'sd1'); |
||
459 | assert.equal(description.getResourceType(), 'http://some/type'); |
||
460 | assert.equal(description.getCitations().length, 1); |
||
461 | assert.equal(description.getCitations()[0].getLang(), 'en'); |
||
462 | assert.equal(description.getCitations()[0].getValue(), 'Long source citation'); |
||
463 | assert.equal(description.getMediaType(), 'book'); |
||
464 | assert.equal(description.getAbout(), 'http://a/resource'); |
||
465 | assert.equal(description.getMediator().getResource(), 'http://mediator'); |
||
466 | assert.equal(description.getSources().length, 1); |
||
467 | assert.equal(description.getSources()[0].getDescription(), 'http://source/reference'); |
||
468 | assert.equal(description.getAnalysis().getResource(), 'http://analysis'); |
||
469 | assert.equal(description.getComponentOf().getDescription(), 'http://container'); |
||
470 | assert.equal(description.getTitles().length, 2); |
||
471 | assert.equal(description.getTitles()[0].getLang(), 'en'); |
||
472 | assert.equal(description.getTitles()[0].getValue(), 'Title'); |
||
473 | assert.equal(description.getTitles()[1].getLang(), 'es'); |
||
474 | assert.equal(description.getTitles()[1].getValue(), 'Titulo'); |
||
475 | assert.equal(description.getNotes().length, 1); |
||
476 | assert.equal(description.getNotes()[0].getSubject(), 'Note'); |
||
477 | assert.equal(description.getNotes()[0].getText(), 'Some note text'); |
||
478 | assert.equal(description.getAttribution().getCreated().getTime(), 1234578129); |
||
479 | assert.equal(description.getRights().length, 1); |
||
480 | assert.equal(description.getRights()[0].getResource(), 'https://some/right'); |
||
481 | assert.equal(description.getCoverage().getTemporal().getFormal(), '+2015'); |
||
482 | assert.equal(description.getCoverage().getSpatial().getOriginal(), 'A place'); |
||
483 | assert.equal(description.getDescriptions().length, 1); |
||
484 | assert.equal(description.getDescriptions()[0].getValue(), 'A description'); |
||
485 | assert.equal(description.getIdentifiers().identifiers.$, 'identifier'); |
||
486 | assert.equal(description.getCreated(), 1000000); |
||
487 | assert.equal(description.getModified(), 11111111); |
||
488 | assert.equal(description.getRepository().getResource(), 'http://repository'); |
||
489 | |||
490 | assert.equal(gedx.getAgents().length, 1); |
||
491 | var agent = gedx.getAgents()[0]; |
||
492 | assert.equal(agent.getId(), 'agent'); |
||
493 | assert.equal(agent.getIdentifiers().identifiers.$, 'ident'); |
||
494 | assert.equal(agent.getNames().length, 1); |
||
495 | assert.equal(agent.getNames()[0].getLang(), 'en'); |
||
496 | assert.equal(agent.getNames()[0].getValue(), 'Name'); |
||
497 | assert.equal(agent.getHomepage().getResource(), 'http://homepage'); |
||
498 | assert.equal(agent.getOpenid().getResource(), 'http://openid'); |
||
499 | assert.equal(agent.getAccounts().length, 1); |
||
500 | assert.equal(agent.getAccounts()[0].getAccountName(), 'jimbo'); |
||
501 | assert.equal(agent.getEmails().length, 1); |
||
502 | assert.equal(agent.getEmails()[0].getResource(), 'http://email'); |
||
503 | assert.equal(agent.getPhones().length, 1); |
||
504 | assert.equal(agent.getPhones()[0].getResource(), 'http://phone'); |
||
505 | assert.equal(agent.getAddresses().length, 1); |
||
506 | assert.equal(agent.getAddresses()[0].getValue(), 'big long address'); |
||
507 | assert.equal(agent.getAddresses()[0].getPostalCode(), '123456'); |
||
508 | assert.equal(agent.getPerson().getResource(), 'http://person'); |
||
509 | |||
510 | assert.equal(gedx.getEvents().length, 1); |
||
511 | var event = gedx.getEvents()[0]; |
||
512 | assert.equal(event.getType(), 'http://gedcomx.org/Marriage'); |
||
513 | assert.equal(event.getDate().getFormal(), '+2002-06-06'); |
||
514 | assert.equal(event.getPlace().getOriginal(), 'Her town, MN'); |
||
515 | assert.equal(event.getRoles().length, 1); |
||
516 | assert.equal(event.getRoles()[0].getPerson().getResource(), 'http://groom'); |
||
517 | assert.equal(event.getRoles()[0].getType(), 'http://gedcomx.org/Participant'); |
||
518 | |||
519 | assert.equal(gedx.getDocuments().length, 1); |
||
520 | var doc = gedx.getDocuments()[0]; |
||
521 | assert.equal(doc.getType(), 'http://gedcomx.org/Abstract'); |
||
522 | assert.equal(doc.getExtracted(), false); |
||
523 | assert.equal(doc.getTextType(), 'plain'); |
||
524 | assert.equal(doc.getText(), 'Lots of text'); |
||
525 | assert.equal(doc.getAttribution().getCreated().getTime(), 123456789); |
||
526 | |||
527 | assert.equal(gedx.getPlaces().length, 1); |
||
528 | var place = gedx.getPlaces()[0]; |
||
529 | assert.equal(place.getNames().length, 1); |
||
530 | assert.equal(place.getNames()[0].getLang(), 'en'); |
||
531 | assert.equal(place.getNames()[0].getValue(), 'Pope\'s Creek, Westmoreland, Virginia, United States'); |
||
532 | assert.equal(place.getType(), 'http://identifier/for/the/place/type'); |
||
533 | assert.equal(place.getPlace().getResource(), 'http://place'); |
||
534 | assert.equal(place.getJurisdiction().getResource(), 'http://jurisdiction'); |
||
535 | assert.equal(place.getLatitude(), 27.9883575); |
||
536 | assert.equal(place.getLongitude(), 86.9252014); |
||
537 | assert.equal(place.getTemporalDescription().getFormal(), '+1899-01-04'); |
||
538 | assert.equal(place.getSpatialDescription().getResource(), 'http://uri/for/KML/document'); |
||
539 | |||
540 | assert.equal(gedx.getRecordDescriptors().length, 1); |
||
541 | var rd = gedx.getRecordDescriptors()[0]; |
||
542 | assert.equal(rd.getId(), 'rd'); |
||
543 | assert.equal(rd.getLang(), 'en-US'); |
||
544 | assert.equal(rd.getFields().length, 1); |
||
545 | assert.equal(rd.getFields()[0].getOriginalLabel(), 'Name'); |
||
546 | assert.equal(rd.getFields()[0].getValues().length, 1); |
||
547 | |||
548 | assert.equal(gedx.getCollections().length, 1); |
||
549 | var collection = gedx.getCollections()[0]; |
||
550 | assert.equal(collection.getId(), 'collection'); |
||
551 | assert.equal(collection.getLang(), 'en-US'); |
||
552 | assert.equal(collection.getContent()[0].getResourceType(), 'http://gedcomx.org/Record'); |
||
553 | assert.equal(collection.getTitle(), 'Collection Title'); |
||
554 | assert.equal(collection.getSize(), 183429102); |
||
555 | assert(GedcomX.Attribution.isInstance(collection.getAttribution())); |
||
556 | |||
557 | assert.jsonSchema(gedx.toJSON(), GedcomXSchema); |
||
558 | } |